package com.peace.hospital.feign.system.controller;

import com.peace.hospital.entity.common.Department;
import com.peace.hospital.entity.common.Staffinfo;
import com.peace.hospital.entity.system.Position;
import com.peace.hospital.entity.system.dto.Dto;
import com.peace.hospital.feign.system.service.ISystemService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 门诊模块*/
@RestController
@RequestMapping("")
public class SystemController {
//
//    // 绑定变量名字和属性，参数封装进类
//    @InitBinder("people")
//    public void initBinderPeople(WebDataBinder binder) {
//        binder.setFieldDefaultPrefix("student.");
//    }
//    // 绑定变量名字和属性，参数封装进类
//    @InitBinder("chargingitems")
//    public void initBinderChargingitems(WebDataBinder binder) {
//        binder.setFieldDefaultPrefix("chargingitems.");
//    }
//    // 绑定变量名字和属性，参数封装进类
//    @InitBinder("patientinformation")
//    public void initBinderPatientinformation(WebDataBinder binder) {
//        binder.setFieldDefaultPrefix("patientinformation.");
//    }
//    // 绑定变量名字和属性，参数封装进类
//    @InitBinder("department")
//    public void initBinderDepartment(WebDataBinder binder) {
//        binder.setFieldDefaultPrefix("department.");
//    }
//
//    @Autowired
//    private ISystemService outpatientDepatmentService;
//
///**添加挂号信息*/
//    @RequestMapping(value = "/add",method = RequestMethod.POST)
//    public String addPeopleRegister(@ModelAttribute("people") People people,@ModelAttribute("chargingitems") Chargingitems chargingitems,@ModelAttribute("patientinformation") Patientinformation patientinformation,@ModelAttribute("department") Department department) {
//        RegistrationEntryDto registrationEntryDto = new RegistrationEntryDto(people,chargingitems,patientinformation,department);
//        return outpatientDepatmentService.addPeopleRegister(registrationEntryDto);
//    }
//
//    /**退号操作*/
//    @RequestMapping(value = "/delete/{pid}",method = RequestMethod.PATCH)
//  //  @RequiresRoles(value = {"root", "system"}, logical = Logical.OR)
//    public String updatePeopleRegisterByid(@PathVariable("pid") Integer pid) {
//        System.out.println(pid);
//        return outpatientDepatmentService.updatePeopleRegisterByid(pid);
//    }
//
//    /**
//     * 通过日期查询挂号信息*/
//    @RequestMapping(value = "/select/{date}",method = RequestMethod.GET)
//    public String findPeopleRegisterByDate(@PathVariable Date date) {
//        return outpatientDepatmentService.findPeopleRegisterByDate(date);
//    }

    @Autowired
    private ISystemService outpatientDepatmentService;

    //首页查询用户
    @RequiresRoles(value = {"root", "system"}, logical = Logical.OR)
    @RequestMapping(value = "/staffinfo/select", method = {RequestMethod.GET})
     public String SelestStaffinfo(){

        return outpatientDepatmentService.SelestStaffinfo();
    }

    // 修改用户
    @RequiresRoles(value = {"root", "system"}, logical = Logical.OR)
    @RequestMapping(value = "/staffinfo/update", method = {RequestMethod.PUT})
    public   String updateStaffinfo(Staffinfo staffinfo , Department department, Position position){
        Dto dto = new Dto();
        dto.setStaffinfo(staffinfo);
        dto.setDepartment(department);
        dto.setPosition(position);
        System.out.println(dto);
        return  outpatientDepatmentService.updateStaffinfo(dto);
    }


    //删除用户
    @RequiresRoles(value = {"root", "system"}, logical = Logical.OR)
    @RequestMapping(value = "/staffinfo/delect/{staid}", method = {RequestMethod.GET})
    public String updateStanstate( HttpServletRequest request, @PathVariable("staid") Integer staid){
        return  outpatientDepatmentService.updateStanstate(request,staid);
    }


    //添加员工
    @RequiresRoles(value = {"root", "system"}, logical = Logical.OR)
    @RequestMapping(value = "/staffinfo/add", method = RequestMethod.POST)
  public   String addStaffinfo(Staffinfo staffinfo , Department department, Position position){
      Dto dto = new Dto();
      dto.setStaffinfo(staffinfo);
      dto.setDepartment(department);
      dto.setPosition(position);
      return   outpatientDepatmentService.addStaffinfo(dto);
    }


    //多条件搜索员工信息
    @RequiresRoles(value = {"root", "system"}, logical = Logical.OR)
    @RequestMapping(value = "/staffinfo/search",method = RequestMethod.GET)
    public String SearchMessage(Staffinfo staffinfo){
        System.out.println(staffinfo);
        return   outpatientDepatmentService.SearchMessage(staffinfo);
    }


}
